FROM centos:7.6.1810

# 清空yum仓库配置并创建新目录
RUN rm -rf /etc/yum.repos.d/* && mkdir -p /etc/yum.repos.d/

# 复制新的仓库配置文件
COPY Centos-Base.repo epel.repo /etc/yum.repos.d/

# 生成yum缓存
RUN yum makecache

# 安装必要的软件包并清理缓存
RUN yum -y install httpd php python-requests mysql-connector-python php-mysql && yum clean all

# 复制配置文件和脚本
COPY php.ini /etc/php.ini
COPY httpd.conf /etc/httpd/conf/httpd.conf
COPY delayed_content.php delayed_download.php security-script-cgi.py view-script-cgi.py view-downfile-cgi.py delete_script.py change_permissions.sh file_handler.py /var/www/cgi-bin/

# 创建日志文件并设置权限
RUN touch /var/log/view-script.log && chmod 777 /var/log/view-script.log && \
    touch /var/log/view-downing.log && chmod 777 /var/log/view-downing.log && \
    touch /var/log/httpd/access_log && touch /var/log/httpd/error_log && \
    ln -sf /dev/stdout /var/log/httpd/access_log && ln -sf /dev/stderr /var/log/httpd/error_log

# 启动服务
CMD ["/bin/bash", "-c", "nohup /var/www/cgi-bin/change_permissions.sh & /usr/sbin/httpd -D FOREGROUND"]
